import { PageTool } from "../../../../common/global/PageTool";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GuildActivityRecommendPanel } from "./GuildActivityRecommendPanel";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { TilePanel } from "../../equipment/TilePanel";
import { ItemCellRenderer } from "../../common/ItemCellRenderer";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { GuildActivityConfigInfo } from "../../../resource/info/GuildActivityConfigInfo";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { ItemData } from "../../../resource/info/ItemData";
//class GuildActivityInfoPanel
    
    export  class GuildActivityInfoPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._pageTool = new PageTool([], 4);
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 212, 395, this);
            ObjCreate.createBg(0, -3, 215, 28, this, ImagesConst.RbListHeader);
            this._titleTxt1 = ObjCreate.createTextField(Language.getString(57503), 0, 0, 215, 30, this, new GTextFormat(FontUtil.lishuName, 20, 16187136));
            this._titleTxt1.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._descTxt = ObjCreate.createTextField("", 20, 40, 175, 120, this);
            this._descTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._descTxt.multiline = true;
            this._descTxt.wordWrap = true;
            ObjCreate.createBg(0, 160, 215, 28, this, ImagesConst.RbListHeader);
            this._titleTxt2 = ObjCreate.createTextField(Language.getString(57504), 0, 165, 215, 30, this, new GTextFormat(FontUtil.lishuName, 20, 16187136));
            this._titleTxt2.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createFlowerBg(0, 187, 212, 208, this);
            this._recommendPanel = new GuildActivityRecommendPanel();
            this._recommendPanel.x = 55;
            this._recommendPanel.y = 195;
            this.addChild(this._recommendPanel);
            ObjCreate.createBg(10, 295, 195, 2, this, ImagesConst.SplitLine);
            ObjCreate.createTextField(Language.getString(57505), 15, 300, 200, 20, this, GlobalStyle.textFormat6);
            var loc1=0;
            while (loc1 < 4) 
            {
                ObjCreate.createBg(25 + loc1 * 43, 325, 38, 38, this, ImagesConst.PackItemBg);
                ++loc1;
            }
            this._itemsList = new TilePanel();
            this._itemsList.setSize(165, 38);
            this._itemsList.rowHeight = 38;
            this._itemsList.columnWidth = 38;
            this._itemsList.horizontalGap = 5;
            this._itemsList.setStyle("cellRenderer", ItemCellRenderer);
            this._itemsList.move(26, 326);
            this.addChild(this._itemsList);
            this._pageBar = new PageSelecter();
            this._pageBar.mode = PageSelecter.SingleMode;
            this._pageBar.x = 70;
            this._pageBar.y = 370;
            this.addChild(this._pageBar);
            this._pageBar.addEventListener(flash.events.Event.CHANGE, this.onChangeHandler);
            return;
        }

        public updateByGuildActivityConfigInfo(arg1: GuildActivityConfigInfo): void
        {
            if (arg1) 
            {
                this._descTxt.htmlText = "<textFormat leading=\'5\'>" + arg1.des + "</textFormat>";
                this._recommendPanel.updateByRecommend(arg1.recommendArray);
                this._pageTool.array = this.getItemDatas(arg1.itemCodes);
                this._pageBar.maxPage = this._pageTool.pagesCount;
                this.onChangeHandler(null);
            }
            return;
        }

        /* internal  */updateDataProvider(arg1: Array<any>): void
        {
            if (this._dataProvider) 
            {
                this._dataProvider.removeAll();
            }
            else 
            {
                this._dataProvider = new DataProvider();
            }
            var loc1=0;
            while (loc1 < arg1.length) 
            {
                this._dataProvider.addItem(arg1[loc1]);
                ++loc1;
            }
            this._itemsList.dataProvider = this._dataProvider;
            return;
        }

        /* internal  */onChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._pageBar.currentPage;
            this.updateDataProvider(this._pageTool.getByPageNo(loc1));
            return;
        }

        /* internal  */getItemDatas(arg1: Array<any>): Array<any>
        {
            var loc2=0;
            var loc1=[];
            var loc3=0;
            while (loc3 < arg1.length) 
            {
                loc2 = int(arg1[loc3]);
                loc1.push(new ItemData(loc2));
                ++loc3;
            }
            return loc1;
        }

        /* internal */ /* var */_titleTxt1: Object /* flash.text.TextField */;

        /* internal */ /* var */_descTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_titleTxt2: Object /* flash.text.TextField */;

        /* internal */ /* var */_recommendPanel: GuildActivityRecommendPanel;

        /* internal */ /* var */_itemsList: TilePanel;

        /* internal */ /* var */_pageBar: PageSelecter;

        /* internal */ /* var */_pageTool: PageTool;

        /* internal */ /* var */_dataProvider: DataProvider;
    }
